package com.kangyi.admin.mapper;

import com.github.pagehelper.Page;
import com.kangyi.admin.annotation.AutoFill;
import com.kangyi.dto.*;
import com.kangyi.vo.AdminUserVO;
import com.kangyi.entity.AdminUser;
import com.kangyi.enumeration.OperationType;
import com.kangyi.vo.DetailNursingHomeAccountVO;
import com.kangyi.vo.ManageAccountPageQueryVO;
import com.kangyi.vo.NursingHomeAccountPageQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@Mapper
public interface AdminUserMapper {


    AdminUser getAdminUser(String name, String phone);


    @Select("select * from admin_user where name = #{name}")
    AdminUser getName(String name);

    @AutoFill(value = OperationType.UPDATE)
    void update(AdminUser adminUser);


    @Update("update admin_user set password = #{newPassword},update_time=#{updateTime},update_user=#{updateUser} where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void updateByPassword(PasswordEditDTO passwordEditDTO);

    @Select("select * from admin_user where id = #{id}")
    AdminUserVO selectById(Integer id);

    @Update("update admin_user set password = #{newPassword} where phone = #{phone}")
    @AutoFill(value = OperationType.UPDATE)
    void forgotPassword(ForgotPasswordDTO forgotPasswordDTO);

    @Update("update admin_user set phone = #{phone} where id = #{id}")
    void updateByPhone(ChangePhoneDTO changePhoneDTO);

    List<AdminUserVO> getAdminUsersByIds(List<Integer> userIds);

    @Select("select * from admin_user where id = #{id};")
    AdminUser getAdminUsersById(Integer id);

    @AutoFill(value = OperationType.INSERT)
    void addAdminUser(AdminUser adminUser);

    Page<ManageAccountPageQueryVO> pageQuery(ManageAccountPageQueryDTO manageAccountPageQueryDTO);

    @Delete("delete from admin_user where id = #{id}")
    void deleteById(Integer id);

    @Update("update admin_user set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id};")
    @AutoFill(value = OperationType.UPDATE)
    void bulkOperation(AdminUser build);

    Page<NursingHomeAccountPageQueryVO> NursingHomeAccountPageQuery(NursingHomeAccountPageQueryDTO nursingHomeAccountPageQueryDTO);

    @Select("select * from admin_user where id = #{id};")
    DetailNursingHomeAccountVO detailAccount(Integer id);

    @Update("update admin_user set nursing_home_id = null where id = #{id};")
    void updateNursingHome(Integer id);

    @Select("select * from admin_user where nursing_home_id = #{nursingHomeId};")
    List<AdminUser> getByNursingHomeId(Integer nursingHomeId);

    @Update("update admin_user set nursing_home_id = null where id = #{id};")
    void updateNursingHomeId(Integer id);
}
